//此文件用来连接数据库
const mysql = require("mysql2");

const config = require("./config");

//创建连接池
const connections = mysql.createPool({
  host: config.MYSQL_HOST,
  port: config.MYSQL_PORT,
  database: config.MYSQL_DATABASE,
  user: config.MYSQL_ROOT,
  password: MYSQL_PASSWORD,
});

connections.getConnection((err, conn) => {
  if (err) {
    console.log("连接失败");
  } else {
    console.log("数据库连接成功");
  }
});

module.exports = connections.promise();
